import {Url} from './Url';
import {Fetch} from './';

export function parseSearch() {
    var resultObj = {};
    var search = window.location.search;
    if (search && search.length > 1) {
        var search = search.substring(1);
        var items = search.split('&');
        for (var index = 0; index < items.length; index++) {
            if (!items[index]) {
                continue;
            }
            var kv = items[index].split('=');
            resultObj[kv[0]] = typeof kv[1] === "undefined" ? "" : kv[1];
        }
    }
    return resultObj;
    if (window.resultObj && window.resultObj.classid) {
        return window.resultObj;
    }
    return Fetch(Url.GET_CLASS, {body: {deviceid: resultObj.clientid}})
        .then((res)=> {
            if (res['class'] && res['class'].classid) {
                resultObj['class'] = res['class'];
                resultObj['school'] = res['school'];
                resultObj['device'] = res['device'];
                resultObj['classroom'] = res['classroom'];
                resultObj['classid'] = res['class'].classid;
                return resultObj;
            } else {
                alert('设备码没有跟班级对应，请核验!')
            }
        })
        .catch(e=> {
            console.log(e)
        })
}

